package org.emet.dao;

//import static org.emet.Constants.DRIVER;
//import static org.emet.Constants.GATHER;
//import static org.emet.Constants.STATUS_OK;

import org.emet.entity.biz.Employee;
import org.emet.jee.core.dao.Page;
import org.emet.jee.core.dao.arch.ArchDataSourceBaseDao;
import org.emet.service.dto.EmployeeCriteria;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class EmployeeDao extends ArchDataSourceBaseDao<Employee, Long> {
	private static final String entityName = Employee.class.getSimpleName();
	String Q_VLIAD_BY_TITILE = "from " + entityName + " where title = ? and status = ?";

	//	public List<Employee> getValidDrivers() {
	//		return find(Q_VLIAD_BY_TITILE, DRIVER, STATUS_OK);
	//	}
	//
	//	public List<Employee> getValidGathers() {
	//		return find(Q_VLIAD_BY_TITILE, GATHER, STATUS_OK);
	//	}

	public Page<Employee> search(Page<Employee> page, EmployeeCriteria criteria) {
		Criteria c = getSession().createCriteria(Employee.class);

		NonEmptyValueHashMap<String, Object> propertyNameValues = new NonEmptyValueHashMap<String, Object>();
		propertyNameValues.put("name", criteria.getName());
		propertyNameValues.put("status", criteria.getStatus());
		propertyNameValues.put("title", criteria.getTitle());

		c.add(Restrictions.allEq(propertyNameValues));
		page.setOrderBy("id");
		page.setOrder("desc");
		return findPage(page, c);
	}

}
